<?php
class ActoresController extends AppController {

	var $name = 'Actores';

	function index() {
		$this->Actore->recursive = 0;
		$this->set('actores', $this->paginate(), array('nombre'=>array('order'=>array('Actore.nombre'=>'ASC'))));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid actore', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('actore', $this->Actore->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Actore->create();
			if ($this->Actore->save($this->data)) {
				$this->Session->setFlash(__('Actor Creado', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('El Actor no se ha creado. Intente de nuevo.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid actore', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Actore->save($this->data)) {
				$this->Session->setFlash(__('Actor Actualizado', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('El Actor no se actualizo. Intente de nuevo.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Actore->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for actore', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Actore->delete($id)) {
			$this->Session->setFlash(__('Actor eliminado', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('El actor no se ha eliminado', true));
		$this->redirect(array('action' => 'index'));
	}
}
